user  {{ openresty_user }};

error_log  {{ openresty_error_log }};
pid        {{ openresty_pidfile }};

worker_processes  {{ openresty_worker_processes }};

events {
    use epoll;
    worker_connections  {{ openresty_worker_connections }};
    multi_accept {{ openresty_multi_accept }};
}
{% if openresty_extra_conf_options %}
{{ openresty_extra_conf_options }}
{% endif %}
http {
    include       {{ openresty_mime_file_path }};
    default_type  application/octet-stream;

    log_format  main  '{"@timestamp": "$time_iso8601", '
                         '"clientRealIp": "$remote_addr", '
                         '"scheme": "$scheme", '
                         '"method": "$request_method", '
                         '"host": "$host", '
                         '"url": "$request_uri", '
                         '"size": $body_bytes_sent, '
                         '"referrer": "$http_referer", '
                         '"agent": "$http_user_agent", '
                         '"upstream_addr": "$upstream_addr", '
                         '"request_time": $request_time, '
                         '"request_length": $request_length, '
                         '"upstream_connect_time": "$upstream_connect_time", '
                         '"upstream_response_time": "$upstream_response_time", '
                         '"upstream_status": "$upstream_status", '
                         '"status": "$status"}';
                         
    log_format  main-json escape=json '{"@timestamp": "$time_iso8601", '
                         '"clientRealIp": "$remote_addr", '
                         '"scheme": "$scheme", '
                         '"method": "$request_method", '
                         '"host": "$host", '
                         '"url": "$request_uri", '
                         '"size": $body_bytes_sent, '
                         '"referrer": "$http_referer", '
                         '"agent": "$http_user_agent", '
                         '"request_body": "$request_body",'
                         '"upstream_addr": "$upstream_addr", '
                         '"request_time": $request_time, '
                         '"request_length": $request_length, '
                         '"upstream_connect_time": "$upstream_connect_time", '
                         '"upstream_response_time": "$upstream_response_time", '
                         '"upstream_status": "$upstream_status", '
                         '"status": "$status"}';
    
    access_log  {{ openresty_access_log }} main;
    
    server_names_hash_bucket_size {{ openresty_server_names_hash_bucket_size }};
    large_client_header_buffers 4 16k;
    client_header_buffer_size 4k;
    client_body_buffer_size 128k;
    client_max_body_size 100m;
    client_header_timeout 2m;
    client_body_timeout 2m;
    send_timeout 2m;

    open_file_cache max=65535 inactive=60s;
    open_file_cache_valid 80s;

    sendfile        {{ openresty_sendfile }};
    tcp_nopush      {{ openresty_tcp_nopush }};
    tcp_nodelay     {{ openresty_tcp_nodelay }};

    keepalive_timeout  {{ openresty_keepalive_timeout }};
    keepalive_requests {{ openresty_keepalive_requests }};
    
{% if openresty_gzip %}
    gzip on;
    gzip_vary on;
    gzip_min_length  1100;
    gzip_comp_level 6;
    gzip_buffers     16 8k;
    #gzip_http_version 1.0;
    gzip_types text/plain text/css image/jpeg image/gif image/png text/javascript application/json application/javascript application/x-javascript application/xml;
{% endif %}

    proxy_buffers 4 128k;
    proxy_buffer_size 128k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
    proxy_max_temp_file_size 256m;
    proxy_send_timeout 120;
    proxy_read_timeout 120;
    proxy_connect_timeout 120;
    #proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
   
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Connection "";
        
    server_tokens off;
    more_clear_headers 'Server';
    proxy_hide_header X-Application-Context;
    underscores_in_headers on;
    
{% if openresty_proxy_cache_path %}
    proxy_cache_path {{ openresty_proxy_cache_path }};
{% endif %}
{% if openresty_extra_http_options %}
    {{ openresty_extra_http_options|indent(4, False) }}
{% endif %}
    include {{ openresty_conf_d_path }}/*.conf;
}
{% if openresty_stream %}
include 00_stream.conf;
{% endif %}
